package de.koller.worlders.engine.entity.enc.gu;

import de.koller.oceanFramework.gl.util.ParticleTexture;
import de.koller.worlders.WSea;
import org.lwjgl.opengl.GL11;

public class TargetV extends WSea {

	private static ParticleTexture texture;
	private float rot = 0;
	
	@Override
	protected void init() {
		super.init();
		
		if( texture == null )
			texture = generate();
	}

	public void renderOver( float x, float y, float size, int elapsedTime ) {
		GL11.glColor3f( 1, 1, 0 );
		renderIntern( x, y, size, elapsedTime );
	}
	
	public void renderTarget( float x, float y, float size, int elapsedTime ) {
		GL11.glColor3f( 1, 0, 0 );
		renderIntern( x, y, size, elapsedTime );
	}
	
	private void renderIntern( float x, float y, float size, int elapsedTime ) {
		rot += elapsedTime * 0.2f;
		
		GL11.glPushMatrix();
		GL11.glTranslatef( x, y, 0 );
		GL11.glRotatef( rot, 0, 0, 1 );
		GL11.glTranslatef( -x, -y, 0 );
		
		texture.draw2D( x-(size/2), y-(size/2), size, size, 10 );
		GL11.glPopMatrix();
	}
	
	public ParticleTexture generate() {
		ParticleTexture.MAG_FILTER = GL11.GL_NEAREST;
		ParticleTexture t = ParticleTexture.generate( 8, 8 );
		
		t.clear( 0 );
		t.setPixel( 0xffffffff, 0, 0 );
		t.setPixel( 0xffffffff, 1, 0 );
		t.setPixel( 0xffffffff, 0, 1 );

		t.setPixel( 0xffffffff, 7, 0 );
		t.setPixel( 0xffffffff, 6, 0 );
		t.setPixel( 0xffffffff, 7, 1 );

		t.setPixel( 0xffffffff, 7, 7 );
		t.setPixel( 0xffffffff, 6, 7 );
		t.setPixel( 0xffffffff, 7, 6 );

		t.setPixel( 0xffffffff, 0, 7 );
		t.setPixel( 0xffffffff, 1, 7 );
		t.setPixel( 0xffffffff, 0, 6 );
		
		t.flush();
		return t;
	}
	
}
